/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.RekapMahasiswaLulusanReguler;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import library.Koneksi;

/**
 *
 * @author user
 */
public class DataLulusanReguler {
    
   RekapMahasiswaLulusanReguler mhsLulusanReguler;
    
    public List<RekapMahasiswaLulusanReguler> daftarMhsLulusanReguler(){
        
        List<RekapMahasiswaLulusanReguler> listMhslulusanregular = new ArrayList<RekapMahasiswaLulusanReguler>();
        Koneksi dbConn = new Koneksi();
//        String sql = "SELECT kuota.TAHUN_AJARAN, kuota.KUOTA_MHS, jumlah_calon_mahasiswa.CALON_MHS_IKUT, jumlah_calon_mahasiswa.CALON_MHS_LULUS "
//                + "FROM jumlah_calon_mahasiswa, kuota "
//                + "WHERE kuota.ID_TAHUN_AJARAN = jumlah_calon_mahasiswa.TAHUN_AJARAN GROUP BY kuota.TAHUN_AJARAN";
        String sql = "Select * from lulusan_reguler";
        PreparedStatement st = null;
        ResultSet rs = null;
        try {

            Connection conn = Koneksi.getKoneksi();

            st = conn.prepareStatement(sql);
            rs = st.executeQuery();

            while(rs.next()){
                String tahun = rs.getString("TAHUN_AKADEMIK");
                
                this.mhsLulusanReguler = new RekapMahasiswaLulusanReguler();
                mhsLulusanReguler.setTahunAkademik(tahun);
                mhsLulusanReguler.setTotalLulusanRegularBukanTransfer(rs.getString("LULUSAN_REG_NONTRANS"));
                mhsLulusanReguler.setTotalLulusanTransfer(rs.getString("LULUSAN_TRANS"));
                mhsLulusanReguler.setIpkMinLulusan(rs.getString("IPK_MIN"));
                mhsLulusanReguler.setIpkRatLulusan(rs.getString("IPK_RATA_RATA"));
                mhsLulusanReguler.setIpkMakLulusan(rs.getString("IPK_MAX"));
                listMhslulusanregular.add(mhsLulusanReguler);
            }
        } catch (SQLException ex) {
            Logger.getLogger(DataLulusanReguler.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                st.close();
            } catch (SQLException ex) {
                Logger.getLogger(DataLulusanReguler.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                rs.close();
            } catch (SQLException ex) {
                Logger.getLogger(DataLulusanReguler.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return listMhslulusanregular;
        
    }
    
    public boolean tambahLulusanReguler(RekapMahasiswaLulusanReguler a){
        boolean hasil = false;
        
        String sql = "insert into lulusan_reguler"
                + "(TAHUN_AKADEMIK, LULUSAN_REG_NONTRANS, "
                + "LULUSAN_TRANS, IPK_MIN, "
                + "IPK_RATA_RATA, IPK_MAX) value"
                + "("+a.getTahunAkademik()+", "+a.getTotalLulusanRegularBukanTransfer()+","
                + a.getTotalLulusanTransfer()+", '"+a.getIpkMinLulusan()+"','"
                + a.getIpkRatLulusan()+"', '"+a.getIpkMakLulusan()+"')";
        
        PreparedStatement st = null;
        Connection conn = Koneksi.getKoneksi();
        try {
            st = conn.prepareStatement(sql);
            hasil = st.execute();
        } catch (SQLException ex) {
            Logger.getLogger(DataLulusanReguler.class.getName()).log(Level.SEVERE, null, ex);
        } finally{
            try {
                st.close();
            } catch (SQLException ex) {
                Logger.getLogger(DataLulusanReguler.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
        return hasil;
    }
    
}
